
#include "S_36_IndicatorLight_doSet.h"
#include "mi_iid_define.h"
#include "spec.h"
#include "main.h"
#include "section1_set_func.h"

static void P_36_1_On_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_BOOLEAN)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.boolean.value;

	LOG_INFO("%s, %d\r\n",__func__,o->value.data.boolean.value);
	

    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
  A85_36_1_Set(o->value.data.boolean.value);
//  BeepStart();		
	
	if(o->value.data.boolean.value == false)
	{
		if(0 == g_BeepActiveFlag)
		{
			BeepStart();
		}
		
		if(GetAppSetFlag() == SH_SET)
		{
			SetAppSetFlag(SH_RESET);
		}		
	}	
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_36_1_On_doChange_notify(o->value->data.boolean.value);

    return;
}

static void P_36_2_Brightness_doSet(property_operation_t *o)
{
    // 判断数据格式是否正确，如果错误，返回代码: OPERATION_ERROR_VALUE
    if (o->value.format != PROPERTY_FORMAT_NUMBER)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

    // 简单判断数据取值范围是否合法，如果不合法，返回代码: OPERATION_ERROR_VALUE
    if (o->value.data.number.value.integerValue < 0 || o->value.data.number.value.integerValue > 2)
    {
        o->code = OPERATION_ERROR_VALUE;
        return;
    }

	if(AirGetSelfCleanModeSwitchState() == SWITCH_ON)
	{
		o->code = OPERATION_ERROR_VALUE;
        return;
	}
	
    // TODO: 执行写操作: o->value.data.number.value.integerValue;

	LOG_INFO("%s, %ld\r\n",__func__,o->value.data.number.value.integerValue);
	
    // 如果成功，返回代码: OPERATION_OK
    o->code = OPERATION_OK;
    
    //上报状态，通知app状态变化，统一APP修改、定时器触发后的上报机制
//    P_36_2_Brightness_doChange_notify(o->value->data.number.value.integerValue);
	A86_36_2_Set(o->value.data.number.value.integerValue);
//	BeepStart();
    return;
}

void S_36_IndicatorLight_doSet(property_operation_t *o)
{
    switch (o->piid)
    {
        case PIID_36_1_On:
            P_36_1_On_doSet(o);
            break;

        case PIID_36_2_Brightness:
            P_36_2_Brightness_doSet(o);
            break;

        default:
            o->code = OPERATION_ERROR_VALUE;
            break;
    }
}
